<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Insert title here</title>
    <link rel="stylesheet" href="__PUBLIC__/js/bootstrapvalidator/css/bootstrapValidator.min.css" />
	<link rel="stylesheet" href="__PUBLIC__/css/bootstrap-datetimepicker.css" />
 	<script type="text/javascript" src="__PUBLIC__/js/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/bootstrap-datetimepicker.js"></script>
</head>
<body>
	<div class="modal-dialog" role="document" style="width:600px;">
	    <div class="modal-content">
	        <div class="modal-header">
	            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	            <h4 class="modal-title" id="exampleModalLabel"><if condition="$id">修改物业费催缴<else/>添加物业费催缴</if></h4>
	        </div>
	        <form class="form-horizontal" style="padding:4%;height:500px;overflow-y:auto;" id="condoFeeForm">
	        	<input type="hidden" name="id" value="{$id}"/>
				<div class="form-group">
					<label class="control-label col-sm-3">所属楼宇:</label>
					<div class="col-sm-8">
						<select name="house_id" class="form-control">
							<foreach name="houses" item="house">
								<option value="{$house.id}" <if condition="$house['id'] eq $condoFee['house_id']">selected</if>>{$house.name}</option>
							</foreach>
						</select>
					</div>
				</div>
	        	<div class="form-group">
                	<label class="control-label col-sm-3">企业名称:</label>
                	<div class="col-sm-8">
                		<input type="text" class="form-control" name="company_name" value="{$condoFee.company_name}" placeholder="请输入企业名称">
                	</div>
            	</div>
				<div class="form-group">
					<label class="control-label col-sm-3">企业手机号:</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" name="contact_phone" value="{$condoFee.contact_phone}" placeholder="请输入企业联系方式">
					</div>
				</div>
				<div class="form-group">
					<label class="control-label col-sm-3">所属楼层:</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" name="floor_info" value="{$condoFee.floor_info}" placeholder="请输入企业所属楼层">
					</div>
				</div>
				<div class="form-group">
					<label class="control-label col-sm-3">房间号:</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" name="room_info" value="{$condoFee.room_info}" placeholder="请输入企业房间号">
					</div>
				</div>
				<div class="form-group">
					<label class="control-label col-sm-3">入驻日期:</label>
					<div class="col-sm-8">
						<div class='input-group date' id='enter_time'>
							<input type='text' value="<if condition="$condoFee['enter_time']">{$condoFee.enter_time|date="Y-m-d",###}</if>" name="enter_time" class="form-control " data-date-format="yyyy-mm-dd" />
							<div class="input-group-addon">
								<span class="glyphicon glyphicon-calendar"></span>
							</div>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label col-sm-3">首次缴费日期:</label>
					<div class="col-sm-8">
						<div class='input-group date' id='first_pay_date'>
							<input type='text' value="<if condition="$condoFee['first_pay_date']">{$condoFee.first_pay_date|date="Y-m-d",###}</if>" name="first_pay_date" class="form-control " data-date-format="yyyy-mm-dd" placeholder="请输入首次或最近一次缴费日期"/>
							<span class="input-group-addon">
								<span class="glyphicon glyphicon-calendar"></span>
							</span>
						</div>
					</div>
				</div>
            	<div class="form-group">
                	<label class="control-label col-sm-3">缴费周期:</label>
                	<div class="col-sm-8">
                		<select class="form-control" name="pay_cycle">
                			<option value="0" <if condition="$condoFee.pay_cycle eq 0">selected</if>>半年</option>
                			<option value="1" <if condition="$condoFee.pay_cycle eq 1">selected</if>>一年</option>
							<option value="2" <if condition="$condoFee.pay_cycle eq 2">selected</if>>两年</option>
							<option value="3" <if condition="$condoFee.pay_cycle eq 3">selected</if>>三年</option>
                		</select>
                	</div>
            	</div>
				<div class="form-group">
					<label class="control-label col-sm-3">物管手机号:</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" name="admin_phone" value="{$condoFee.admin_phone}" placeholder="请输入物管联系方式">
					</div>
				</div>
            	<input type="hidden" name="token" value="{$formToken}">
	        </form>
	        <div class="modal-footer">
	            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
	            <button type="button" id="save" class="btn btn-primary">保存</button>
	        </div>
	    </div>
	</div>
    
    <div class="modal fade" id="modal_map"></div>
	<script type="text/javascript">
		var webRoot = "__ROOT__";
		$(function(){
            $('#enter_time').datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'ch',
                pickDate: true,
                pickTime: false,
                autoclose:true,
                minView:2,
            });
            $('#first_pay_date').datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'ch',
                pickDate: true,
                pickTime: false,
                autoclose:true,
                minView:2,
            }).on('hide',function(e) {
                var bv = $('#condoFeeForm').data('bootstrapValidator');
                if(bv){
                    bv.updateStatus('first_pay_date', 'NOT_VALIDATED',null).validateField('first_pay_date');
                }
            });
			$("#save").bind("click",doSave);
		});
		
		var commitFlag = false;
		function doSave(){
			if(commitFlag){
				common.alert("提示","请勿重复提交");
				return;
			}
			commitFlag = true;
			if(!validateForm()){
				commitFlag = false;
				return false;
			}
			$.ajax({
                url: "{:U('Admin/CondoFee/add')}",
                type: "post",
                dataType: "json",
                data: $("#condoFeeForm").serialize(),
                success: function (data) {
                    if(data.status){
                    	common.alert("提示",data.msg,function(){
                            common.reload();
                        });
                    }else{
                    	commitFlag = false;
                    	common.alert("提示",data.msg);
                    }
                }
            });
		}

		function validateForm(){
			$('#condoFeeForm').bootstrapValidator({
				feedbackIcons: {
            　　　　　　　　		valid: 'glyphicon glyphicon-ok',
            　　　　　　　　		//invalid: 'glyphicon glyphicon-remove',
            　　　　　　　　		validating: 'glyphicon glyphicon-refresh'
        　　　　　　　　 	},
	            fields: {
                    house_id: {
                        validators: {
                            notEmpty: {
                                message: '所属楼宇不能为空'
                            }
                        }
                    },
                    company_name: {
	                    validators: {
	                        notEmpty: {
	                            message: '企业名称不能为空'
	                        }
	                    }
	                },
                    contact_phone: {
                        validators: {
                            notEmpty: {
                                message: '企业手机号不能为空'
                            },
                            regexp: {
                                regexp: /^((((13|14|15|18|17)[0-9]{1}))+\d{8})$/,
                                message: '无效的手机号码'
                            }
                        }
                    },
                    admin_phone: {
                        validators: {
                            notEmpty: {
                                message: '物管手机号不能为空'
                            },
                            regexp: {
                                regexp: /^((((13|14|15|18|17)[0-9]{1}))+\d{8})$/,
                                message: '无效的手机号码'
                            }
                        }
                    },
                    first_pay_date: {
                        validators: {
                            notEmpty: {
                                message: '首次缴费日期不能为空'
                            }
                        }
                    },
	            }
	        });
			var data = $('#condoFeeForm').data('bootstrapValidator');
		    if (data) {
		        data.validate();
		        if (!data.isValid()) {
		            return false;
		        }
		    }
		    return true;
		}
	</script>
</body>
</html>